<?php

function report_karyawan(){
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'), 
		'nik'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),   
		'nama'=>array('style'=>'border-bottom:2px solid;width:30%'),  
		'tmb'=>array('style'=>'border-bottom:2px solid;width:20%'), 		
		'jabatan'=>array('style'=>'border-bottom:2px solid;width:25%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	
	if(isset($_GET['key'])){
		$query = "
			SELECT * FROM karyawan a 
			INNER JOIN biodata b ON a.biodata_id = b.biodata_id
			WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian)  
			AND ( b.nama LIKE '%{$_GET['key']}%' OR a.nik ='{$_GET['key']}' )
			
		";
	}else{
		$query = "
				SELECT * FROM karyawan a 
				INNER JOIN biodata b ON a.biodata_id = b.biodata_id
				WHERE karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
				AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 
				ORDER BY a.nik		
		";
		
	}

if(isset($_GET['th']))echo $query;	
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =15;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com=kekaryawanan&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 15; 
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatans = my_get_data_by_id('jabatan','jabatan_id',( isset($karyawan['jabatan_id']) ? $karyawan['jabatan_id'] : 0 ));
		

		$fingerproperty = array(
			'href'=>'index.php?com=kekaryawanan&task=set_finger&kid='.$ey['karyawan_id'], 
			'title'=>'Edit finger ID',
			'rel'=>'facebox'
			);
		$efinger_button_admin = button_icon( 's_rights.png' , $fingerproperty  );

		$editproperty_admin = array(
			'href'=>'index.php?com=kekaryawanan&task=edit&id='.$ey['karyawan_id'], 
			'title'=>'Edit'
		);
		$edit_button_admin = button_icon( 'b_edit.png' , $editproperty_admin  );
		$editproperty_standar = array(
				'href'=>'javascript:;',
				'onclick'=>'alert(\'Akses di tolak\')',
				'title'=>'Edit'
		);
		$edit_button_standar = button_icon( 'b_edit.png' , $editproperty_standar  );
		$edit_button = admin_link( $edit_button_admin , $edit_button_standar );

		$detailproperty = array(
			'href'=>'index.php?com=kekaryawanan&task=detail&id='.$ey['karyawan_id'],
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		$jabatans = my_get_data_by_id('jabatan','jabatan_id',( isset($karyawan['jabatan_id']) ? $karyawan['jabatan_id'] : 0 ));
		if(empty($karyawan['gelar'])){
			$nama_karyawan=ucfirst($karyawan['nama']) ;
		}else{
			$nama_karyawan=trim(ucfirst($karyawan['nama'])).", ".$karyawan['gelar'] ;
		}	

		$row[] = array(
			'#'=>position_text_align ($i, 'center'),
			'nik'=>position_text_align( $karyawan['nik'], 'center'),
			'nama'=>$nama_karyawan,  
			'tmb'=>date( 'd - m - Y' , strtotime($karyawan['tmb']) ),  
			'jabatan'=> $jabatans['nama_jabatan'],  
			'operasi'=> position_text_align( $detail_button .' '.$edit_button.' '.$efinger_button_admin, 'right'),  
		);
	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" /><span style="font:10px verdana"><b>Pencarian cepat</b></span><br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" /><input class="simple_search" type="submit" value=" CARI " /> </form>';
	$menuontop = array(  
		'Export to excel'=>array('onclick'=>'javascript:location.href=\'index.php?com='.$_GET['com'].'&task=excel_daftar_kekaryawan\''),
		//'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=all_karyawan\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
	);
	$printmenu = additional_menu_on_list($menuontop, $search);
	return $printmenu  . table_builder($header , $datas ,  15 ,false , $paging  );
} 

function form_edit($id =0){
	my_set_file_js(array('components/system/js/calendar/calendarDateInput.js','components/system/jquery/combomulti/jquery.chainedSelects.js')); 
	$fields = my_get_data_by_id('kekaryawanan' ,'karyawan_id',$id);
	
	$karyawan =  loaddata_karyawan($id);  
	$jabatan =  loaddata_jabatan( $karyawan['jabatan_id']);  
	$view = form_header( "..." , "..."  );

	$npwp = array(
		'name'=>'npwp',
		'value'=>( isset($_POST['npwp'] ) ? $_POST['npwp'] : $fields['npwp']  ),
		'id'=>'npwp' , 
		'type'=>'text',
		'size'=>'25' ,
	);
	$form_npwp= form_dynamic($npwp );
	$view .= form_field_display( $form_npwp , "NPWP"    );
	
	$jamsostek = array(
		'name'=>'jamsostek',
		'value'=>( isset($_POST['jamsostek'] ) ? $_POST['jamsostek'] : $fields['jamsostek']  ),
		'id'=>'jamsostek' , 
		'type'=>'text',
		'size'=>'25' ,
	);
	$form_jamsostek= form_dynamic($jamsostek );
	$view .= form_field_display( $form_jamsostek , "Jamsostek"    );

	$view .= form_field_display( 'Rp. '.rp_format($fields['gapok_km'] ) , "Gaji Pokok KM"    );
	
	$gapok_ks = array(
		'name'=>'gapok_ks',
		'value'=>( isset($_POST['gapok_ks'] ) ? $_POST['gapok_ks'] : rp_format($fields['gapok_ks'])  ),
		'id'=>'gapok_ks' , 
		'type'=>'text',
		'size'=>'35' ,
	);
	$form_gapok_ks = form_money($gapok_ks );
	$view .= form_field_display( $form_gapok_ks  , "Gaji Pokok KS"    );

	$email_km = array(
		'name'=>'email_km',
		'value'=>( isset($_POST['email_km'] ) ? $_POST['email_km'] :  $fields['email_km']  ),
		'id'=>'email_km' , 
		'type'=>'text',
		'size'=>'35' ,
	);
	$form_email_km = form_dynamic($email_km );
	$view .= form_field_display( $form_email_km  , "Email KMH"    );

	$ppmp = array(
		'name'=>'ppmp',
		'value'=>( isset($_POST['ppmp'] ) ? $_POST['ppmp'] : rp_format($fields['ppmp'])  ),
		'id'=>'ppmp' , 
		'type'=>'text',
		'size'=>'35' ,
	);
	$form_ppmp = form_money($ppmp );
	$view .= form_field_display( $form_ppmp  , "PhDP PPMP"    );
	
	$ppip = array(
		'name'=>'ppip',
		'value'=>( isset($_POST['ppip'] ) ? $_POST['ppip'] : rp_format($fields['ppip'])  ),
		'id'=>'ppip' , 
		'type'=>'text',
		'size'=>'35' ,
	);
	$form_ppip = form_money($ppip );
	$view .= form_field_display( $form_ppip  , "PhDP PPIP"    );
	
	$query = "SELECT * FROM bank ORDER BY bank ASC";
	$result = my_query($query);
	$temps = array();
	while( $r = my_fetch_array($result) ){
		$temps[$r['bank_id']] =$r['bank'];
	}	
	$temp = array(
		'name'=>'bank_id',
		'value'=>( isset($_POST['bank_id'] ) ? $_POST['bank_id'] : $fields['bank_id']  ),
		'id'=>'bank_id'  
	);
	$form_temp = form_dropdown($temp , $temps );
	$view .= form_field_display( $form_temp , "Nama Bank"    );

	$norek = array(
		'name'=>'norek',
		'value'=>( isset($_POST['norek'] ) ? $_POST['norek'] : $fields['norek']  ),
		'id'=>'norek' , 
		'type'=>'text',
		'size'=>'25' ,
	);
	$form_norek= form_dynamic($norek );
	$view .= form_field_display( $form_norek , "Nomer Rekening"    );	

	$query = "SELECT * FROM profesi ORDER BY profesi_id ASC";
	$result = my_query($query);
	$profesis = array();
	while( $r = my_fetch_array($result) ){
		$profesis[$r['profesi_id']] =$r['nama_profesi'];
	}
	$profesi = array(
		'name'=>'profesi_id',
		'value'=>( isset($_POST['profesi_id'] ) ? $_POST['profesi_id'] : $fields['profesi_id']  ),
		'id'=>'profesi_id'  
	);
	$form_profesi = form_dropdown($profesi , $profesis );
	$view .= form_field_display( $form_profesi , "Profesi"    );

	$query = "SELECT * FROM profesi_detail ORDER BY profesi_detail_id ASC";
	$result = my_query($query);
	$profesi_details = array();
	while( $r = my_fetch_array($result) ){
		$profesi_details[$r['profesi_detail_id']] =$r['nama_profesi_detail'];
	}
	$profesi_detail = array(
		'name'=>'profesi_detail_id',
		'value'=>( isset($_POST['profesi_detail_id'] ) ? $_POST['profesi_detail_id'] : $fields['profesi_detail_id']  ),
		'id'=>'profesi_detail_id'  
	);
	$form_profesi_detail = form_dropdown($profesi_detail , $profesi_details );
	$view .= form_field_display( $form_profesi_detail , "Profesi Detail"    );

	$form_status_insentif ='';
	$opsi_status = array('paid'=>'Paid','unpaid'=>'Unpaid');
	$status_insentif = array(
		'name'=>'status_insentif','id'=>'status_insentif',
		'value'=>isset($_POST['status_insentif']) ? $_POST['status_insentif'] : $fields['status_insentif'] 
	);
	$form_status_insentif .= form_radiobutton($status_insentif , $opsi_status);
	$view .= form_field_display( $form_status_insentif , "Status Insentif"    );
	
	$opsi_ptkp = array( 
		'K'=>'K', 
		'TK'=>'TK', 
	);
	$ptkp_status = array(
		'name'=>'ptkp_status',
		'id'=>'ptkp_status',
		'value'=>isset($_POST['ptkp_status']) ? $_POST['ptkp_status'] : $fields['ptkp_status'] 
	); 
	
	$opsi_tanggungan = array( 
		'0'=>'0',
		'1'=>'1',
		'2'=>'2',
		'3'=>'3',
		'4'=>'4',
		'5'=>'5',
		'6'=>'6',
		'7'=>'7',
		'8'=>'8',
		'9'=>'9'
	);
	$ptkp_tanggung = array(
		'name'=>'ptkp_tanggung',
		'id'=>'ptkp_tanggung',
		'value'=>isset($_POST['ptkp_tanggung']) ? $_POST['ptkp_tanggung'] : $fields['ptkp_tanggung'] 
	); 
	$form_ptkp_status=  form_dropdown($ptkp_status , $opsi_ptkp).
			'&nbsp; &nbsp; &nbsp; Tanggungan : '. form_dropdown($ptkp_tanggung , $opsi_tanggungan);
	
	$view .= form_field_display( $form_ptkp_status , "P T K P"    );
	$kelompok_shifts = array();
	$query_kelompok_shift = "SELECT a.kelompok_shift_id,b.label,a.kelompok_shift_kode FROM a_kelompok_shift a 
		INNER JOIN a_waktu_kerja b ON a.waktu_kerja_id=b.waktu_kerja_id 
		ORDER BY a.kelompok_shift_id ";
	 $re = my_query($query_kelompok_shift);
	 while($row = my_fetch_array($re) ){
		$kelompok_shifts[$row['kelompok_shift_id']] =$row['label'].'/'.$row['kelompok_shift_kode'];
	 }
	 $kelompok_shift = array(
		'name'=>'kelompok_shift_id',
		'id'=>'kelompok_shift_id',
		'value'=>isset($_POST['kelompok_shift_id']) ? $_POST['kelompok_shift_id'] : $fields['kelompok_shift_id'] 
		);
	$form_field_kelompok_shift = form_dropdown($kelompok_shift , $kelompok_shifts);
	$view .= form_field_display( $form_field_kelompok_shift   , "Tipe Waktu Kerja/Kelompok");

	if($fields['finger_diabaikan']=='Y'){ 
		$finger_diabaikan = array(
			'name'=>'finger_diabaikan',
			'id'=>'finger_diabaikan',
			'type'=>'checkbox',
			'checked'=>'checked'
		);
	}else{
		$finger_diabaikan = array(
			'name'=>'finger_diabaikan',
			'id'=>'finger_diabaikan',
			'type'=>'checkbox',
		); 
	}
	$view .= form_field_display( form_dynamic($finger_diabaikan)." diabaikan" , "Finger Print" );

	$datas = array(
		'S'=>'S',
		'D'=>'D',
	);
	$premi_kesehatan = array(
		'name'=>'premi_kesehatan',
		'id'=>'premi_kesehatan',
		'value'=>isset($_POST['premi_kesehatan']) ? $_POST['premi_kesehatan'] : $fields['premi_kesehatan'],
	);
	$form_premi_kesehatan = form_dropdown($premi_kesehatan , $datas);
	$view .= form_field_display( $form_premi_kesehatan , "Premi Kesehatan" );
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit);
	$kk = array(
		'value' => ( 'Kembali'),
		'name' => 'simpan', 
		'type'=>'button',
		'onclick'=>'javascript:location.href=(\'index.php?com=kekaryawanan\')',
		'class'=>'main_button'
	);
	$form_kk= form_dynamic($kk); 
	
	$view .= form_field_display( $form_submit .' '.$form_kk , "&nbsp;" ,  "" );
	$view .= form_footer( );
	$pro = karyawan_header_detail($karyawan, true, $newline  );
	return $pro.$view;
}

function form_submit_kekaryawanan($karyawan_id){
	$lembur = isset($_POST['lembur']) ? 'Ya': 'Tidak';
	$finger_diabaikan = isset($_POST['finger_diabaikan']) ? 'Y': 'T';
	$karyawan = loaddata_karyawan($karyawan_id);
	list($dd,$mm,$yyyy) = explode("-" , $_POST['tmb']);
	$tanggal = $yyyy .'-'. $mm . '-' . $dd ;
	
/*	
	//biodata
	$adadata=my_get_data_by_id('biodata','biodata_id',$karyawan['biodata_id']);
	if($adadata){
		$datas = array(
			'tanggal_diterima'		=>my_type_data_str($_POST['tanggal_diterima']),
		);	
		my_update_record( 'biodata' , 'biodata_id' , $karyawan['biodata_id'] , $datas );
	}
*/	
	//kekaryawanan
	$adadata=my_get_data_by_id('kekaryawanan','karyawan_id',$karyawan_id);
	if($adadata){
	}else{
		$datas = array(
			'karyawan_id'	=>my_type_data_int($karyawan_id),
		);
		my_insert_record('kekaryawanan' , $datas);
	}
	
	$datas = array(
		'npwp'		=>my_type_data_str($_POST['npwp']),
		'jamsostek'		=>my_type_data_str($_POST['jamsostek']),
		'gapok_ks'	=>my_type_data_str( set_text_as_number( $_POST['gapok_ks'] ) ),
		'ppmp'	=>my_type_data_str( set_text_as_number( $_POST['ppmp'] ) ),
		'ppip'	=>my_type_data_str( set_text_as_number( $_POST['ppip'] ) ),
		'bank_id'		=>my_type_data_int($_POST['bank_id']),
		'norek'		=>my_type_data_str($_POST['norek']),
		'profesi_id'	=>my_type_data_int($_POST['profesi_id']),
		'profesi_detail_id'	=>my_type_data_int($_POST['profesi_detail_id']),
		'status_insentif' =>my_type_data_str($_POST['status_insentif']),
		'ptkp_status' =>my_type_data_str($_POST['ptkp_status']),
		'ptkp_tanggung' =>my_type_data_str($_POST['ptkp_tanggung']),
		'kelompok_shift_id'	=>my_type_data_int($_POST['kelompok_shift_id']),
		'finger_diabaikan'=>my_type_data_str($finger_diabaikan),	
		'premi_kesehatan'	=>my_type_data_str($_POST['premi_kesehatan']),
		'email_km'	=>my_type_data_str($_POST['email_km']),
	);
	my_update_record( 'kekaryawanan' , 'karyawan_id' , $karyawan_id , $datas );
	create_data_karyawan_json($karyawan_id);
	
	return true;
}

function form_submit_validate($karyawan_id){
	$errsubmit = false;
	$err = array();
		
 	if( !valid_email_address($_POST['email_km'])){
		$errsubmit = true;
		$err[] ="Alamat email belum benar";
	}
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function form_detail($id){
	my_set_code_js('
		function confirmDelete( task ,i){
		var check = confirm(\'Akan mendelete data? \'); 
		if(check){
			location.href=\'index.php?com=remove_node_karyawan&task=\'+ task +\'&id=\'+i;
		}
		return;	}
	'); 
	$karyawan = loaddata_karyawan($id); 
	
	
	$tab_options = array(
		'Karir'=>'tab1',
		'Diklat'=>'tab2',
		'Remunerasi'=>'tab3',
		'Tatib'=>'tab4',
		'Kompetensi'=>'tab5',
		'Uraian Pekerjaan'=>'tab6',
		'Cuti'=>'tab7',
	);
	$cuti_table = __cuti($karyawan);
	$tanggung_jawab_table = __tanggung_jawab($karyawan);
	$kompetensi_table = __kompetensi($id);
	$tatib_table =  __tatib($id);
	$jabatan_table  = __jabatan($id);
	$remunerasi_table = __renumerasi($id);
	$pelatihan_table= __pelatihan($id);
	$contents = array(
		'tab1'=>$jabatan_table ,
		'tab2'=>$pelatihan_table,
		'tab3'=>$remunerasi_table,
		'tab4'=>$tatib_table,
		'tab5'=>$kompetensi_table,
		'tab6'=>$tanggung_jawab_table,
		'tab7'=>$cuti_table
	); 
	$tabcontents = tab_page($tab_options , $contents );
	$newline=array(
		'NPWP'=>$karyawan['npwp'].'&nbsp; &nbsp;  &nbsp; &nbsp;  <b>Jamsostek :</b> '.$karyawan['jamsostek'],
		'Nipar'=>get_nipar_by_karyawan_id($id).'&nbsp; &nbsp;  &nbsp; &nbsp;  <b>Lembur :</b> '.$karyawan['lembur']   
	);
	$pro = karyawan_header_detail($karyawan, true, $newline  ); 
	$menuontop = array(  
		'Back' => array('onclick'=>'javascript:location.href=\'index.php?com=kekaryawanan'.'\'')
	);
	$printmenu = additional_menu_on_list( $menuontop , '');
	unset($_SESSION['tab_page']);
	return $pro.$printmenu.$view.$tabcontents ;
	
}
function __pelatihan($id){

	
	//pelatihan
	$header = array(
		'mulai'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'sampai'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'pelatihan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'kategori'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'materi'=>array('style'=>'border-bottom:2px solid;width:25%'),    
		'hasil'=>array('style'=>'border-bottom:2px solid;width:5%'),   
		' '=>array('style'=>'border-bottom:2px solid;width:5%'),   
	);
	
	$sort_tgl = array();
	$query = "SELECT tanggal_mulai,kekaryawanan_pelatihan_id,2 as type 
		FROM kekaryawanan_pelatihan
		WHERE karyawan_id={$id}
		 ";
	$dres = my_query($query);
	while($dey = my_fetch_array($dres)){
		$sort_tgl[] = array(
			'tanggal'=>$dey['tanggal_mulai'] ,
			'type'=>$dey['type'] ,
			'id'=>$dey['kekaryawanan_pelatihan_id'] ,
		);
	}

	$query = "SELECT 
		a.jadwal_pelatihan_id as id,
		b.tanggal_mulai,
		1 as type FROM karyawan_pelatihan a
		INNER JOIN jadwal_pelatihan b
			ON a.jadwal_pelatihan_id = b.jadwal_pelatihan_id		
		WHERE a.karyawan_id={$id}
	 ";

	$dres = my_query($query);
	while($dey = my_fetch_array($dres)){
		$sort_tgl[] = array(
			'tanggal'=>$dey['tanggal_mulai'] ,
			'type'=>$dey['type'] ,
			'id'=>$dey['id'] ,
		);
	}	

	$ncnt=0;;
	$row=array() ;
	if(is_array($sort_tgl) ){
		rsort($sort_tgl);
		foreach ($sort_tgl as $section => $items){
			$tipe=$sort_tgl[$section]['type'] ;
			$tgl=$sort_tgl[$section]['tanggal'] ;
			$keyid=$sort_tgl[$section]['id'] ;
			if($tipe==1){ //penempatan
				$query = "SELECT 
					b.tanggal_sampai,
					b.nama_pelatihan as pelatihan, 
					c.kategori_pelatihan_label as kategori, 
					d.materi_pelatihan_label as materi, 
					a.hasil 
					FROM karyawan_pelatihan a
					INNER JOIN jadwal_pelatihan b
						ON a.jadwal_pelatihan_id = b.jadwal_pelatihan_id		
					INNER JOIN kategori_pelatihan c
						ON c.kategori_pelatihan_id = b.kategori_pelatihan_id
					INNER JOIN materi_pelatihan d 
						ON d.materi_pelatihan_id=b.materi_pelatihan_id 
					WHERE a.karyawan_id={$id} 
					AND a.jadwal_pelatihan_id ={$keyid} 
					LIMIT 1
				 ";
				$pelatihans = my_fetch_array(my_query($query)) ;
				$edit_button = ' ';
				$delete_button = ' ';				
				$row[] = array(
					'tgl_mulai'=>DATE('d-m-Y', strtotime($tgl)), 
					'tgl_sampai'=>DATE('d-m-Y', strtotime($pelatihans['tanggal_sampai'])), 
					'pelatihan'=> $pelatihans['pelatihan'],
					'kategori'=>$pelatihans['kategori'],
					'materi'=>$pelatihans['materi'],
					'hasil'=> $pelatihans['hasil'],	
					'operasi'=> position_text_align( $edit_button.' '.$delete_button, 'right'),  			
				); 				
			}else{
				$pelatihans=my_get_data_by_id('kekaryawanan_pelatihan','kekaryawanan_pelatihan_id',$keyid);
				$editproperty = array(
					'href'=>'index.php?com=kekaryawanan&task=edit_pelatihan&kid='.$id.'&id='.$keyid,
					'rel'=>'facebox',
					'title'=>'Edit'
				);	
				$edit_button = button_icon( 'b_edit.png' , $editproperty  );
				$deleteproperty = array(
					'href'=>'javascript:; ',
					'onclick'=>'javascript:confirmDelete( \'edit_pelatihan\' ,'.$keyid.');',
					'title'=>'Delete'
				);
				$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );

				$row[] = array(
					'tgl_mulai'=>DATE('d-m-Y', strtotime($tgl)), 
					'tgl_sampai'=>DATE('d-m-Y', strtotime($pelatihans['tanggal_sampai'])), 
					'pelatihan'=> $pelatihans['pelatihan'],
					'kategori'=>$pelatihans['kategori'],
					'materi'=>$pelatihans['materi'],
					'hasil'=> $pelatihans['hasil'],	
					'operasi'=> position_text_align( $edit_button.' '.$delete_button, 'right'),  			
				); 		
			}
		}
		$ncnt++;		
	}	
 	//var_dump($ncnt) ; exit;
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'tgl_mulai'=> '&nbsp;',  
				'tgl_sampai'=> '&nbsp;',  
				'pelatihan'=>  '&nbsp;', 
				'kategori'=>  '&nbsp;', 
				'materi'=> '&nbsp;', 
				'hasil'=> '&nbsp;', 
				'operasi'=> '&nbsp;', 
			); 
		}
	}

	$pelatihantabs = table_rows_plain($row); 
	$pelatihan_table = table_builder_plain($header , $pelatihantabs ,  4,false );
	$pelatihan_table  .= '<div style="text-align:right;width:100%;font:12px verdana;">'.admin_link('<a href="index.php?com=kekaryawanan&task=edit_pelatihan&kid='.$id.'&id=0" rel="facebox">[Tambah data]</a>').'</div><br/>'; 
	return $pelatihan_table; 
}

function __renumerasi($id){
	$karyawan = loaddata_karyawan($id);
	$karyawan_status_id = $karyawan['status_kekaryawan_id'];
	$st = array(
		'1'=>'Organik',
		'2'=>'Kontrak',
		'3'=>'Perbantuan',
		'4'=>'Alih_Status',
	);
	$status = strtolower($st[$karyawan_status_id]);
	$status = (trim($status) <> '') ? $status : $st[1];
	//CEK PERAWAT
	if($karyawan['profesi_detail_id']==0){
		$query_perawat=" AND model_entry<> 4 ";
	}else{
		$query_perawat="" ;
	}	
	//remunerasi
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Nama Komponen'=>array('style'=>'text-align:left;border-bottom:2px solid;width:70%'),  
		'Tipe'=>array('style'=>'text-align:left;border-bottom:2px solid;width:5%'),  
		'Nominal'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);	

	$gapok= $karyawan['gapok_km'] ;

	$query = "SELECT nama_komponen_gaji, tipe, komponen_gaji_id
		FROM pr_komponen_gaji 
		WHERE remunerasi='Y'  
		AND (model_entry<>2 OR
		( model_entry=2 AND ".$status."='yes'))".$query_perawat;
	$query .=" ORDER BY tipe, nama_komponen_gaji";	
	$dres = my_query($query);
	$row = array();
	$ncnt=1;;
	$row[] = array(
		'nno'=>$ncnt ,
		'nama'=>'Gaji Pokok' ,
		'tipe'=>' ',
		'tot'=> position_text_align(rp_format($gapok), 'right' ),
		'op'=> position_text_align(' ' , 'right' ),
	);
	
	$tipes = array(
		'1'=>'Tunjangan',
		'2'=>'Potongan',
		'3'=>'Iuran',
	);			

	while($r = my_fetch_array($dres) ){
		$nominal=kalkulasi_komponen($r['komponen_gaji_id'] , $id);
		if($nominal>0){
			$ncnt++;
			$row[] = array(
				'nno'=> $ncnt,
				'nama'=>$r['nama_komponen_gaji'] ,
				'tipe'=>$tipes[$r['tipe']],
				'tot'=> position_text_align(rp_format($nominal), 'right' ),
			); 
		}
	}
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'nama'=> '&nbsp;',  
				'tipe'=> '&nbsp;',  
				'tot'=>  '&nbsp;', 
			); 
		}
	}
	$datas = table_rows_plain($row); 
	$remunerasi_table = table_builder_plain($header , $datas ,  4,false );

	return $remunerasi_table;
}

function __jabatan($id){

	//jabatan
	$header_jabatan = array(
		'Efektif'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'No. Pos'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Departemen'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Direktorat'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Gol'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Grade'=>array('style'=>'border-bottom:2px solid;width:10%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:5%'),
	);


	$sort_tgl = array();
	$query = "SELECT tanggal,2 as type,kekaryawanan_jabatan_id as id 
		FROM kekaryawanan_jabatan 
		WHERE karyawan_id={$id}
		 ";
	$dres = my_query($query);
	while($dey = my_fetch_array($dres)){
		$sort_tgl[] = array(
			'tanggal'=>$dey['tanggal'] ,
			'type'=>$dey['type'] ,
			'id'=>$dey['id'] ,
		);
	}
	$query = "SELECT b.tanggal_efektif as tanggal,1 as type, a.seleksi_internal_detail_id  as id 
		FROM penempatan_detail a  
		INNER JOIN penempatan b ON b.seleksi_internal_id=a.seleksi_internal_id 
	 	WHERE a.karyawan_id={$id}	
	 ";
	$dres = my_query($query);
	while($dey = my_fetch_array($dres)){
		$sort_tgl[] = array(
			'tanggal'=>$dey['tanggal'] ,
			'type'=>$dey['type'] ,
			'id'=>$dey['id'] ,
		);
	}	
	$ncnt=0;
	$row=array() ;
	if(is_array($sort_tgl) ){
		rsort($sort_tgl);
		foreach ($sort_tgl as $section => $items){
		
			$tipe=$sort_tgl[$section]['type'] ;
			$tgl=$sort_tgl[$section]['tanggal'] ;
			$keyid=$sort_tgl[$section]['id'] ;
			if($tipe==1){ //penempatan
				$karirs=my_get_data_by_id('penempatan_detail','seleksi_internal_detail_id',$keyid);
				$jabatan = loaddata_jabatan($karirs['posisi_baru_id']); 	
				$golongan_jabatan_id=( isset($karirs['golongan_jabatan_id']) ? $karirs['golongan_jabatan_id'] : 0 ) ;
				$golongan_jabatans=my_get_data_by_id('golongan_jabatan','golongan_jabatan_id',$golongan_jabatan_id);
				$grade_id=( isset($karirs['grade_id']) ? $karirs['grade_id'] : 0 ) ;
				$grades=my_get_data_by_id('grade','grade_id',$grade_id);
				$edit_button = ' ';
				$delete_button = ' ';				
				$row[] = array(
					'tgl'=>DATE('d-m-Y', strtotime($tgl)), 
					'no_org'=> $jabatan['nomor_organisasi'],
					'jabatan'=>$jabatan['nama_jabatan'],
					'dept'=>$jabatan['organisasi_departemen'],
					'dir'=> $jabatan['organisasi_direktorat'],	
					'gol'=> $golongan_jabatans['kode_golongan_jabatan'],   
					'grade'=>$grades['kode_grade'],   
					'operasi'=> position_text_align( $edit_button.' '.$delete_button, 'right'),  			
				); 				
			}else{
				$karirs=my_get_data_by_id('kekaryawanan_jabatan','kekaryawanan_jabatan_id',$keyid);
				$editproperty = array(
					'href'=>'index.php?com=kekaryawanan&task=edit_jabatan&kid='.$id.'&id='.$keyid,
					'rel'=>'facebox',
					'title'=>'Edit'
				);	
				$edit_button = button_icon( 'b_edit.png' , $editproperty  );
				$deleteproperty = array(
					'href'=>'javascript:; ',
					'onclick'=>'javascript:confirmDelete( \'edit_jabatan\' ,'.$keyid.');',
					'title'=>'Delete'
				);
				$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		
				$row[] = array(
					'tgl'=>DATE('d-m-Y', strtotime($tgl)), 
					'no_org'=> $karirs['no_organisasi'],   
					'jabatan'=>$karirs['jabatan'],   
					'dept'=>$karirs['departemen'],   
					'dir'=> $karirs['direktorat'],   
					'gol'=> $karirs['golongan_jabatan'],   
					'grade'=>$karirs['grade'],   
					'operasi'=> position_text_align( $edit_button.' '.$delete_button, 'right'),  			
				); 
			}
		}
		$ncnt++;		
	}	
 
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'tgl'=> '&nbsp;',  
				'no_org'=> '&nbsp;',  
				'jabatan'=>  '&nbsp;', 
				'dept'=>  '&nbsp;', 
				'dir'=> '&nbsp;', 
				'gol'=> '&nbsp;', 
				'grade'=> '&nbsp;', 
				'tab'=> '&nbsp;', 
			); 
		}
	}
	$jabatans = table_rows_plain($row); 
	
	$jabatan_table = table_builder_plain($header_jabatan , $jabatans ,  4,false );
	$jabatan_table  .= '<div style="text-align:right;width:100%;font:12px verdana;">'.admin_link('<a href="index.php?com=kekaryawanan&task=edit_jabatan&kid='.$id.'&id=0" rel="facebox">[Tambah data]</a>').'</div><br/>'; 
	return $jabatan_table;
}

function __tatib($id){

	//tatib
	$header = array(
		'Tanggal'=>array('style'=>'text-align:left;border-bottom:2px solid;width:10%'),  
		'Nomor Surat'=>array('style'=>'text-align:left;border-bottom:2px solid;width:20%'),  
		'Peringatan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:20%'),  
		'Uraian'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),  
		'Sangsi'=>array('style'=>'text-align:left;border-bottom:2px solid;width:20%'),  
	);

	$query = "SELECT b.tanggal , b.nomor, c.nama_jenis_peringatan, a.uraian, a.sangsi    
		FROM tatib_detail a
		INNER JOIN tatib b ON b.tatib_id=a.tatib_id
		INNER JOIN jenis_peringatan c ON c.jenis_peringatan_id=a.jenis_peringatan_id 
		WHERE a.karyawan_id={$id} 
		ORDER BY b.tanggal";
	$dres = my_query($query);
		
	$ncnt=0;		
	$row = array();
	while($dey = my_fetch_array($dres)){
		$row[] = array(
			'tgl'=>date( 'd-m-Y' , strtotime($dey['tanggal']) ) ,  
			'nomor'=>strtoupper($dey['nomor'] ),   
			'prgt'=>$dey['nama_jenis_peringatan'],
			'ur'=> $dey['uraian'],
			's'=> $dey['sangsi'],
		);
		$ncnt++;		
	}
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'tgl'=> '&nbsp;',  
				'nomor'=> '&nbsp;',  
				'prgt'=>  '&nbsp;', 
				'ur'=>  '&nbsp;', 
				's'=> '&nbsp;', 
			); 
		}
	}
	$datas = table_rows_plain($row); 
	return table_builder_plain($header , $datas ,  4,false );	
}

function __kompetensi($id){

	//kompetensi
	$header = array(
		'kelompok'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'unit'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'kompetensi'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'indikator'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:5%'),
	);
	$query = "SELECT * FROM kekaryawanan_kompetensi a
		INNER JOIN kompetensi b ON a.kompetensi_id = b.kompetensi_id
		INNER JOIN kompetensi_unit  c ON b.kompetensi_unit_id = c.kompetensi_unit_id
		INNER JOIN kompetensi_kelompok d ON d.kompetensi_kelompok_id = c.kompetensi_kelompok_id
		INNER JOIN kompetensi_indikator e ON e.tingkat_id = a.skor AND e.kompetensi_id = a.kompetensi_id 
		WHERE  a.karyawan_id ={$id}";
	 
	$dres = my_query($query);
	$row = array();
	$ncnt=0;;
	while($r = my_fetch_array($dres) ){
		$editproperty = array(
			'href'=>'index.php?com=kekaryawanan&task=edit_kompetensi&kid='.$id.'&id='.$r['pa_atasan_id'],
			'rel'=>'facebox',
			'title'=>'Edit'
		);	
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );
		$deleteproperty = array(
			'href'=>'javascript:; ',
			'onclick'=>'javascript:confirmDelete( \'edit_kompetensi\' ,'.$r['pa_atasan_id'].');',
			'title'=>'Delete'
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );

		$row[] = array(
			'kelompok'=>$r['nama_kompetensi_kelompok'], 
			'unit'=>$r['nama_kompetensi_unit'], 
			'kompetensi'=>$r['nama_kompetensi'], 
			'indikator'=>$r['indikator'], 
			'operasi'=> position_text_align( $edit_button.' '.$delete_button, 'right'),  			
		); 
		$ncnt++;
	}
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'kelompok'=> '&nbsp;',  
				'unit'=> '&nbsp;',  
				'kompetensi'=>  '&nbsp;', 
				'indikator'=>  '&nbsp;', 
				'tab'=> '&nbsp;', 
			); 
		}
	}
	$datas = table_rows_plain($row); 
	$kompetensi_table = table_builder_plain($header , $datas ,  4,false );
	return $kompetensi_table. '<div style="text-align:right;width:100%;font:12px verdana;">'.admin_link('<a href="index.php?com=kekaryawanan&task=edit_kompetensi&kid='.$id.'&id=0" rel="facebox">[Tambah data]</a>').'</div><br/>'; 

	
	
}

function __tanggung_jawab($karyawan){
//tanggung jawab
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Uraian Pekerjaan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:95%'),  
	);
	
	$jabatan_id=$karyawan['jabatan_id'] ;

	$row = array();
	$ncnt=1;
	$uraians = my_get_data_by_id('jabatan','jabatan_id',$jabatan_id);

	$row[] = array(
		'nno'=>$ncnt ,
		'uraian'=>$uraians['job_summary'] ,
	);

	$query = "SELECT * FROM jabatan_tanggung_jawab a
		WHERE a.jabatan_id ={$jabatan_id}";

	$dres = my_query($query);
	while($r = my_fetch_array($dres) ){
		$ncnt++;
		$row[] = array(
			'nno'=> $ncnt,
			'uraian'=>$r['tanggung_jawab'] ,
		); 
	}
	if($ncnt < 5){
		for($ycc=$ncnt; $ycc<=4; $ycc++){
			$row[] = array(
				'nno'=> '&nbsp;',  
				'uraian'=> '&nbsp;',  
			); 
		}
	}
	$datas = table_rows_plain($row); 
	return  table_builder_plain($header , $datas ,  4,false );
	
}

function __cuti($karyawan){
	
	//cuti
	$header = array(
		'Tanggal'=>array('style'=>'text-align:center;border-bottom:2px solid;width:30%'),  
		'Jenis Cuti'=>array('style'=>'text-align:left;border-bottom:2px solid;width:50%'),  
		'Jumlah Hari'=>array('style'=>'text-align:left;border-bottom:2px solid;width:20%'),  
	);
	$row = array();
	$ncnt=1;;

	for($ycc=$ncnt; $ycc<=4; $ycc++){
		$row[] = array(
			'tgl'=> '&nbsp;',  
			'jenis'=> '&nbsp;',  
			'hari'=>  '&nbsp;', 
		); 
	}
	$datas = table_rows_plain($row); 
	return table_builder_plain($header , $datas ,  4,false );
}
function form_edit_jabatan($kekaryawanan_jabatan_id){

	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);

	$fields =  my_get_data_by_id('kekaryawanan_jabatan','kekaryawanan_jabatan_id',$kekaryawanan_jabatan_id); 
	$view = form_header( "calon karyawan" , "cp"  );
	$ftanggal = date('d-m-Y');
	if($fields){
		list($yyyytanggal , $mmtanggal,$ddtanggal ) = explode("-" ,$fields['tanggal'] );
		$ftanggal = $ddtanggal.'-'.$mmtanggal.'-'.$yyyytanggal;
	}

	$tanggal = array(
			'name'=>'tanggal',
			'value'=>(isset($_POST['tanggal'])? $_POST['tanggal'] : $ftanggal),
			'id'=>'tanggal',
		);
	$form_tanggal = form_calendar($tanggal);
	$view .= form_field_display( $form_tanggal  , "Tanggal " );
	
	$no_organisasi = array(
		'name'=>'no_organisasi',
		'value'=>( isset($_POST['no_organisasi']) ? $_POST['no_organisasi'] : $fields['no_organisasi'] ),
		'id'=>'no_organisasi',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_no_organisasi = form_dynamic($no_organisasi);
	$view .= form_field_display( $form_field_no_organisasi   , "Nomor Organisasi"    );	
	
	$jabatan = array(
		'name'=>'jabatan',
		'value'=>( isset($_POST['jabatan']) ? $_POST['jabatan'] : $fields['jabatan'] ),
		'id'=>'jabatan',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_jabatan = form_dynamic($jabatan);
	$view .= form_field_display( $form_field_jabatan   , "Jabatan"    );
	
	$departemen = array(
		'name'=>'departemen',
		'value'=>( isset($_POST['departemen']) ? $_POST['departemen'] : $fields['departemen'] ),
		'id'=>'departemen',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_departemen = form_dynamic($departemen);
	$view .= form_field_display( $form_field_departemen   , "Departemen"    );

	$direktorat = array(
		'name'=>'direktorat',
		'value'=>( isset($_POST['direktorat']) ? $_POST['direktorat'] : $fields['direktorat'] ),
		'id'=>'direktorat',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_direktorat = form_dynamic($direktorat);
	$view .= form_field_display( $form_field_direktorat   , "Direktorat"    );

	$golongan_jabatan = array(
		'name'=>'golongan_jabatan',
		'value'=>( isset($_POST['golongan_jabatan']) ? $_POST['golongan_jabatan'] : $fields['golongan_jabatan'] ),
		'id'=>'golongan_jabatan',
		'type'=>'text',
		'size'=>'5' 
	);
	$form_field_golongan_jabatan = form_dynamic($golongan_jabatan);
	$view .= form_field_display( $form_field_golongan_jabatan   , "Golongan Jabatan"    );
	
	$grade = array(
		'name'=>'grade',
		'value'=>( isset($_POST['grade']) ? $_POST['grade'] : $fields['grade'] ),
		'id'=>'grade',
		'type'=>'text',
		'size'=>'5' 
	);
	$form_field_grade = form_dynamic($grade);
	$view .= form_field_display( $form_field_grade   , "Grade"    );

	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}


function validate_edit_jabatan($karyawan_id, $kekaryawanan_jabatan_id=0){
	$errsubmit = false;
	$err = array();
/*	 
	$nama =  trim($_POST["nama_grievance_kelompok"]); 
	if( $nama == ''){
		$errsubmit = true;
		$err[] = "Kelompok grievance belum diisi";
	}

	$query="SELECT grievance_kelompok_id FROM grievance_kelompok 
		WHERE nama_grievance_kelompok='".$nama.
		"' AND grievance_periode_id=".$pid. 
		" AND grievance_kelompok_id<>".$grievance_kelompok_id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Kelompok grievance sudah ada";	
	}
 */   
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}


function submit_edit_jabatan($karyawan_id, $kekaryawanan_jabatan_id){
	if($_POST){
		list( $ddtanggal, $mmtanggal,$yyyytanggal ) = explode("-" ,$_POST['tanggal'] );
		$ftanggal = $yyyytanggal.'-'.$mmtanggal.'-'.$ddtanggal;
	}

	$datas = array(
		'karyawan_id'		=> my_type_data_int($karyawan_id),
		'tanggal'			=> my_type_data_str($ftanggal),
		'jabatan'			=> my_type_data_str($_POST['jabatan']),
		'no_organisasi'		=> my_type_data_str($_POST['no_organisasi']),
		'departemen'		=> my_type_data_str($_POST['departemen']),
		'direktorat'		=> my_type_data_str($_POST['direktorat']),
		'golongan_jabatan'	=> my_type_data_str($_POST['golongan_jabatan']),
		'grade'				=>my_type_data_str($_POST['grade']),
	);
	if($kekaryawanan_jabatan_id > 0){
		return my_update_record('kekaryawanan_jabatan','kekaryawanan_jabatan_id',$kekaryawanan_jabatan_id,$datas);
	}else{
		return my_insert_record('kekaryawanan_jabatan',$datas);
	}
	
}
//===============================================================

function form_edit_pelatihan($karyawan_id, $kekaryawanan_pelatihan_id){

	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);

	$fields =  my_get_data_by_id('kekaryawanan_pelatihan','kekaryawanan_pelatihan_id',$kekaryawanan_pelatihan_id); 
	$view = form_header( "calon karyawan" , "cp"  );

	$tgl_mulai = date('d-m-Y');
	if($fields){
		list($yyyy_mulai , $mm_mulai,$dd_mulai ) = explode("-" ,$fields['tanggal_mulai'] );
		$tgl_mulai = $dd_mulai.'-'.$mm_mulai.'-'.$yyyy_mulai;
	}
	$tanggal_mulai = array(
			'name'=>'tanggal_mulai',
			'value'=>(isset($_POST['tanggal_mulai'])? $_POST['tanggal_mulai'] : $tgl_mulai),
			'id'=>'tanggal_mulai',
		);
	$form_tanggal = form_calendar($tanggal_mulai);
	$view .= form_field_display( $form_tanggal  , "Tanggal Mulai" );

	$tgl_sampai = date('d-m-Y');
	if($fields){
		list($yyyy_sampai , $mm_sampai,$dd_sampai ) = explode("-" ,$fields['tanggal_sampai'] );
		$tgl_sampai = $dd_sampai.'-'.$mm_sampai.'-'.$yyyy_sampai;
	}

	$tanggal_sampai = array(
			'name'=>'tanggal_sampai',
			'value'=>(isset($_POST['tanggal_sampai'])? $_POST['tanggal_sampai'] : $tgl_sampai),
			'id'=>'tanggal_sampai',
		);
	$form_tanggal = form_calendar($tanggal_sampai);
	$view .= form_field_display( $form_tanggal  , "Tanggal Sampai" );	
	
	$pelatihan = array(
		'name'=>'pelatihan',
		'value'=>( isset($_POST['pelatihan']) ? $_POST['pelatihan'] : $fields['pelatihan'] ),
		'id'=>'pelatihan',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_pelatihan = form_dynamic($pelatihan);
	$view .= form_field_display( $form_field_pelatihan   , "Pelatihan"    );	
	
	$kategori = array(
		'name'=>'kategori',
		'value'=>( isset($_POST['kategori']) ? $_POST['kategori'] : $fields['kategori'] ),
		'id'=>'kategori',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_pelatihan = form_dynamic($kategori);
	$view .= form_field_display( $form_field_pelatihan   , "Kategori"    );	

	$materi = array(
		'name'=>'materi',
		'value'=>( isset($_POST['materi']) ? $_POST['materi'] : $fields['materi'] ),
		'id'=>'materi',
		'type'=>'text',
		'size'=>'45' 
	);
	$form_field_pelatihan = form_dynamic($materi);
	$view .= form_field_display( $form_field_pelatihan   , "Materi"    );	

	$hasil_datas = array(
			'lulus'=>'Lulus',
			'gagal'=>'Gagal',
			'absen'=>'Absen'
		);
	$hasil = array(
				'name'=>'hasil',
				'value'=>( isset($_POST['hasil']) ? $_POST['hasil'] : $fields['hasil'] ),
				'id'=>'hasil', 
			);
	$form_field_hasil = form_dropdown($hasil , $hasil_datas);
	$view .= form_field_display( $form_field_hasil   , "Hasil penilaian"   );	
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}


function validate_edit_pelatihan($karyawan_id, $kekaryawanan_pelatihan_id=0){
	$errsubmit = false;
	$err = array();
/*	 
	$nama =  trim($_POST["nama_grievance_kelompok"]); 
	if( $nama == ''){
		$errsubmit = true;
		$err[] = "Kelompok grievance belum diisi";
	}

	$query="SELECT grievance_kelompok_id FROM grievance_kelompok 
		WHERE nama_grievance_kelompok='".$nama.
		"' AND grievance_periode_id=".$pid. 
		" AND grievance_kelompok_id<>".$grievance_kelompok_id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Kelompok grievance sudah ada";	
	}
 */   
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}


function submit_edit_pelatihan($karyawan_id, $kekaryawanan_pelatihan_id){
	if($_POST){
		list( $dd_mulai, $mm_mulai,$yyyy_mulai ) = explode("-" ,$_POST['tanggal_mulai'] );
		$tanggal_mulai = $yyyy_mulai.'-'.$mm_mulai.'-'.$dd_mulai;
		list( $dd_sampai, $mm_sampai,$yyyy_sampai ) = explode("-" ,$_POST['tanggal_sampai'] );
		$tanggal_sampai = $yyyy_sampai.'-'.$mm_sampai.'-'.$dd_sampai;
	}

	$datas = array(
		'karyawan_id'		=> my_type_data_int($karyawan_id),
		'tanggal_mulai'		=> my_type_data_str($tanggal_mulai),
		'tanggal_sampai'	=> my_type_data_str($tanggal_sampai),
		'pelatihan'			=> my_type_data_str($_POST['pelatihan']),
		'kategori'			=> my_type_data_str($_POST['kategori']),
		'materi'			=> my_type_data_str($_POST['materi']),
		'hasil'				=>my_type_data_str($_POST['hasil']),
	);
	if($kekaryawanan_pelatihan_id > 0){
		return my_update_record('kekaryawanan_pelatihan','kekaryawanan_pelatihan_id',$kekaryawanan_pelatihan_id,$datas);
	}else{
		return my_insert_record('kekaryawanan_pelatihan',$datas);
	}
	
}

function detail_entry($karyawan_id){
	$karyawan = loaddata_karyawan($karyawan_id);
	$view  = form_header( "detail karyawan" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawan['nama']).'</span>'   , "<b>Nama pelamar</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['email'] .'</span>'  , "<b>Email</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['idcard'] .'</span>'  , "<b>Nomor identitas</b>"    );  
	$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawan['kelamin']) .'</span>'  , "<b>Jenis kelamin</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['gol_da'] .'</span>'  , "<b>Golongan darah</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawan['tempat_lahir'] ) .', '.   date('d M Y',strtotime($karyawan['tanggal_lahir'].' 00:00:01')).'</span>' , "<b>Tempat, tanggal lahir</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['marital'] .'</span>'  , "<b>Status perkawinan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['agama']   .'</span>'  , "<b>Agama</b>"    );  
	$view .= form_field_display( '<span class="label_form">'.$karyawan['telepon_rumah'] .'</span>'  , "<b>Nomor telepon rumah</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawan['telepon_mobile'].'</span>'  , "<b>Nomor telepon seluler</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.nl2br($karyawan['alamat'] ).'</span>'  , "<b>Alamat</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawan['kota'] ).'</span>'  , "<b>Kota</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.nl2br($karyawan['catatan'] ).'</span>'  , "<b>Catatan</b>"    ); 
	$submit = array(
		'value' => ( 'Lanjut'),
		'name' => 'simpan', 
		'type'=>'button',
		'onclick'=>'javascript:location.href=(\'index.php?com=profil_kepegawaian&task=create&id='.$karyawan_id.'\')',
		'class'=>'main_button'
	);
	$form_submit = form_dynamic($submit);
	$kk = array(
		'value' => ( 'Kembali'),
		'name' => 'simpan', 
		'type'=>'button',
		'onclick'=>'javascript:location.href=(\'index.php?com=karyawan\')',
		'class'=>'main_button'
	);
	$form_kk= form_dynamic($kk); 
	$ubah = array(
		'value' => ( 'Ubah'),
		'name' => 'simpan', 
		'type'=>'button',
		'onclick'=>'javascript:location.href=(\'index.php?com=karyawan&task=edit&id='.$karyawan_id.'&status=new\')',
		'class'=>'main_button'
	);
	$form_ubah= form_dynamic($ubah); 
	
	$view .= form_field_display( $form_kk .' '.$form_ubah  	  , "&nbsp;" ,  "" );	
	$view .= form_footer( ); 
	
	return $view;
}


function form_edit_kompetensi($karyawan_id, $kekaryawanan_kompetensi_id){

	$fields =  my_get_data_by_id('kekaryawanan_kompetensi','kekaryawanan_kompetensi_id',$kekaryawanan_kompetensi_id); 
	$view = form_header( " " , " "  );

	if($fields){
		$kompetensis = my_get_data_by_id('kompetensi','kompetensi_id',$fields['kompetensi_id']); 
		$uni_kompetensi = my_get_data_by_id('kompetensi_unit','kompetensi_unit_id',$kompetensis['kompetensi_unit_id']);
		$kel_kompetensi = my_get_data_by_id('kompetensi_kelompok','kompetensi_kelompok_id',$uni_kompetensi['kompetensi_kelompok_id']);
	}
	
	$datas_kelompok_kompetensi = array();
	$query_kelompok_kompetensi = "SELECT * FROM kompetensi_kelompok";
	$result_kelompok_kompetensi = my_query($query_kelompok_kompetensi);
	while($row_kelompok_kompetensi = my_fetch_array($result_kelompok_kompetensi)){
		$datas_kelompok_kompetensi[$row_kelompok_kompetensi['kompetensi_kelompok_id']] = $row_kelompok_kompetensi['nama_kompetensi_kelompok'];
	}
	
	$dirkom = array(
				'name'=>'kategori_kompetensi_id',
				'value'=>( isset($_POST['kategori_kompetensi_id']) ? $_POST['kategori_kompetensi_id'] :$uni_kompetensi['kompetensi_kelompok_id'] ),
				'id'=>'kategori_kompetensi_id',
				'type'=>'text',
				'size'=>'45'
			);
	$form_field_kelompok_kompetensi = form_dropdown($dirkom , $datas_kelompok_kompetensi);
 
	$unitkom = array( 
				'name'=>'kompetensi_unit_id',
				'value'=>( isset($_POST['kompetensi_unit_id']) ? $_POST['kompetensi_unit_id'] : ( $fields ? $uni_kompetensi['kompetensi_unit_id'] : 0 ) ),
				'id'=>'kompetensi_unit_id',
		);
	$dropdown_extend = dropdown_multi_rows_extends( $dirkom , $unitkom , $datas_kelompok_kompetensi , "combobox_unit_kompetensi.php"  );
	$view .= form_field_display( $dropdown_extend['parent']  , "Kelompok kompetensi"  ); 

	if($fields){
		$datas_unit_kompetensi = array();
		$query_unit_kompetensi = "SELECT * FROM kompetensi_unit WHERE kompetensi_kelompok_id = {$uni_kompetensi['kompetensi_kelompok_id']}";
		$result_unit_kompetensi = my_query($query_unit_kompetensi);
		while($row_unit_kompetensi = my_fetch_array($result_unit_kompetensi)){
			$datas_unit_kompetensi[$row_unit_kompetensi['kompetensi_unit_id']] = $row_unit_kompetensi['nama_kompetensi_unit'];
		}
		$kompetensi = array( 
				'name'=>'kompetensi_id',
				'value'=>( isset($_POST['kompetensi_id']) ? $_POST['kompetensi_id'] : $fields['kompetensi_id'] ),
				'id'=>'kompetensi_id',
		);
		$dropdown_extend = dropdown_multi_rows_extends( $unitkom , $kompetensi , $datas_unit_kompetensi , "combobox_kompetensi.php"  );
	
		$view .= form_field_display( $dropdown_extend['parent']  , 'Unit kompetensi' );
	}else{	
		$view .= form_field_display( $dropdown_extend['child']  , 'Unit kompetensi' );
	}
	
	$kompetensi = array( 
				'name'=>'kompetensi_id',
				'value'=>( isset($_POST['kompetensi_id']) ? $_POST['kompetensi_id'] : $fields['kompetensi_id'] ),
				'id'=>'kompetensi_id',
	);
	
	if($fields){
		$kompetesi_list = array();
		$query_kompetensi = "SELECT * FROM kompetensi  WHERE kompetensi_unit_id = {$uni_kompetensi['kompetensi_unit_id']}";
		$result_kompetensi = my_query($query_kompetensi);
		while($row_kompetensi = my_fetch_array($result_kompetensi)){
			$len = $row_kompetensi['nama_kompetensi'];
			if( strlen($len) >  65 ) 
			$kompetesi_list[$row_kompetensi['kompetensi_id']] = substr($row_kompetensi['nama_kompetensi'] ,0 ,  65)." ..."  ; 
			else
			$kompetesi_list[$row_kompetensi['kompetensi_id']] = $row_kompetensi['nama_kompetensi'];
		}
		$indikator = array( 
			'name'=>'skor',
			'value'=>( isset($_POST['skor']) ? $_POST['skor'] : $fields['skor'] ),
			'id'=>'skor',
		);
		$dropdown_extend2 = dropdown_multi_rows_extends(   $kompetensi ,  $indikator ,$kompetesi_list, "combobox_kompetensi.php"  );
		$view .= form_field_display( $dropdown_extend2['parent']  , 'Kompetensi' );
	}else{	
		$dropdown_extend2 = dropdown_multi_rows_extends(   $unitkom ,  $kompetensi ,false, "combobox_kompetensi.php"  );
		$view .= form_field_display( $dropdown_extend2['child']  , 'Kompetensi' );
	}	

	$indikator = array( 
		'name'=>'skor',
		'value'=>( isset($_POST['skor']) ? $_POST['skor'] : $fields['skor'] ),
		'id'=>'skor',
	);
	if($fields){
		$indikator_list = array();
		$query_indikator = "SELECT * FROM kompetensi_indikator  WHERE kompetensi_id = {$kompetensis['kompetensi_id']}";
		$result_indikator = my_query($query_indikator);
		while($row_indikator = my_fetch_array($result_indikator)){
			$len = $row_indikator['tingkat_id'].'-'.$row_indikator['indikator'];
			if( strlen($len) >  65 ) 
			$indikator_list[$row_indikator['tingkat_id']] = substr($row_indikator['tingkat_id'].'-'.$row_indikator['indikator'] ,0 ,  65)." ..."  ; 
			else
			$indikator_list[$row_indikator['tingkat_id']] = $row_indikator['tingkat_id'].'-'.$row_indikator['indikator'];
		}
		$dropdown_extend3 = dropdown_multi_rows_extends(   $indikator , false ,$indikator_list, "combobox_indikator.php"  );
		$view .= form_field_display( $dropdown_extend3['parent']  , 'Indikator' );
	}else{	
		$dropdown_extend3 = dropdown_multi_rows_extends(   $kompetensi ,  $indikator ,false, "combobox_indikator.php"  );
		$view .= form_field_display( $dropdown_extend3['child']  , 'Indikator' );
	}	

	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}


function validate_edit_kompetensi($karyawan_id, $pa_atasan_id=0){
	$errsubmit = false;
	$err = array();
/*	 
	$nama =  trim($_POST["nama_grievance_kelompok"]); 
	if( $nama == ''){
		$errsubmit = true;
		$err[] = "Kelompok grievance belum diisi";
	}

	$query="SELECT grievance_kelompok_id FROM grievance_kelompok 
		WHERE nama_grievance_kelompok='".$nama.
		"' AND grievance_periode_id=".$pid. 
		" AND grievance_kelompok_id<>".$grievance_kelompok_id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Kelompok grievance sudah ada";	
	}
 */   
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}

function submit_edit_kompetensi($karyawan_id, $kekaryawanan_kompetensi_id){

	$datas = array(
		'kompetensi_id'		=> my_type_data_int($_POST['kompetensi_id']), 
		'karyawan_id'		=> my_type_data_int($karyawan_id),
		'skor'				=> my_type_data_int($_POST['skor']),
	);
	if($pa_atasan_id > 0){
		return my_update_record('kekaryawanan_kompetensi','kekaryawanan_kompetensi_id',$kekaryawanan_kompetensi_id,$datas);
	}else{
		return my_insert_record('kekaryawanan_kompetensi',$datas);
	}
}



function export_to_excel(){
	my_component_load('xl_builder' , false);
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;'),  
		'Name'=>array('style'=>'border-bottom:2px solid;'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;'),  
		'NIK LM'=>array('style'=>'border-bottom:2px solid;'),  
		'NIK_KS'=>array('style'=>'border-bottom:2px solid;'),  
  
	   	'TMB'=>array('style'=>'border-bottom:2px solid;'),  
		'TMBKONTRAK'=>array('style'=>'border-bottom:2px solid;'),
		'RESIGN'=>array('style'=>'border-bottom:2px solid;'),
		'CCC'=>array('style'=>'border-bottom:2px solid;'),  
		'UNIT'=>array('style'=>'border-bottom:2px solid;'),
		  
		'JENIS KELAMIN'=>array('style'=>'border-bottom:2px solid;'),
		'AGAMA'=>array('style'=>'border-bottom:2px solid;'),
		'PENDIDIKAN'=>array('style'=>'border-bottom:2px solid;'),
		'TGL LAHIR'=>array('style'=>'border-bottom:2px solid;'),
		
		'Grade'=>array('style'=>'border-bottom:2px solid;'),  
		'SALARY'=>array('style'=>'border-bottom:2px solid;'), 
		'SAL KS'=>array('style'=>'border-bottom:2px solid;'), 
		'Golongan'=>array('style'=>'border-bottom:2px solid;'),  
		'KEL KARYAWAN'=>array('style'=>'border-bottom:2px solid;'),
		
 
		
		'JOBCODE'=>array('style'=>'border-bottom:2px solid;'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;'),  
		'Premi'=>array('style'=>'border-bottom:2px solid;'),  
		
		'PPMP'=>array('style'=>'border-bottom:2px solid;'),  
		'PPIP'=>array('style'=>'border-bottom:2px solid;'),  
		'Bank'=>array('style'=>'border-bottom:2px solid;'),  
		'Rekening'=>array('style'=>'border-bottom:2px solid;'),  
		
		'PTKP'=>array('style'=>'border-bottom:2px solid;'),  
		'NPWP'=>array('style'=>'border-bottom:2px solid;'),  
		'JAMSOSTEK'=>array('style'=>'border-bottom:2px solid;'),  
	);
	
	$query = "
		SELECT * FROM karyawan a 
		INNER JOIN biodata b ON a.biodata_id = b.biodata_id
		INNER JOIN kekaryawanan c ON a.karyawan_id = c.karyawan_id
WHERE a.karyawan_id NOT IN  (  SELECT karyawan_id FROM karyawan_disable   ) 
AND  a.karyawan_id NOT IN  (  SELECT karyawan_id FROM pemberhentian   ) 
		GROUP BY a.nik
		ORDER BY  a.karyawan_id ,a.biodata_id  DESC 		
	";
	
	$result = my_query($query);
	$row = array();
	$i = 0;
	$exists = array(); 
	while($ey =my_fetch_array($result)){
		$i++;  
 
		$jabatan = loaddata_jabatan($ey['jabatan_id']);
		//$posbiaya = my_get_data_by_id('pos_biaya','pos_biaya_id' ,$jabatan['pos_biaya_id']);
		$grade = my_get_data_by_id('grade','grade_id',$ey['grade_id']);
		$gol = my_get_data_by_id('golongan_jabatan','golongan_jabatan_id',$ey['golongan_jabatan_id']);
		$pendidikan = my_get_data_by_id( 'pendidikan','pendidikan_id', $ey['riwayat_pendidikan_id']);
		$bank = my_get_data_by_id('bank','bank_id',$ey['bank_id']);
		$status_id=isset($ey['status_id']) ? $ey['status_id'] : 0; 
		$statuss=my_get_data_by_id('status_kekaryawanan','status_id',$status_id);
	    if(in_array($ey['nik'] ,$exists )){ continue; }
		else { $exists[] = $ey['nik_lm'];}
		$tmt = get_tgl_resign($ey['karyawan_id']);
		$row[] = array(
			'no'=>$i,
			'nama'=>$ey['nama'],
			'nik'=>'\''.sprintf('%07d' ,$ey['nik']),
			'niklm'=>(trim($ey['nik_lm']) ==''? ' ' : '\''.sprintf('%07d' ,$ey['nik_lm']) ),
			'nikks'=>(trim($ey['nik_ks']) ==''? ' ' : '\''.sprintf('%07d' ,$ey['nik_ks']) ),
			
			'tmb'=>$ey['tmb'],
			'tmblama'=>$ey['tmb_perumahan'], 
			'resign'=>($tmt ? $tmt : ''),
			'ccc'=>$jabatan['pos_biaya'],
			'unit'=>get_pos_biaya_label_by_code($jabatan['pos_biaya']),
			
			'kelamin'=>strtoupper($ey['kelamin']),
			'agama'=>strtoupper($ey['agama']),
			'pendidikan'=>$pendidikan['label'].'-'.$pendidikan['major'],
			
			'tgl'=>$ey['tanggal_lahir'],
			
			'grade'=>$grade['kode_grade'],
			'salary'=>$ey['gapok_km'],
			'kssalary'=>$ey['gapok_ks'],
			'gol'=>$gol['kode_golongan_jabatan'],
			'status'=>$statuss['label'],

			'jobcode'=>'\''.sprintf('%08d' ,$jabatan['nomor_posisi']),
			'jabatan'=>$jabatan['nama_jabatan'],
			
			'premi'=>$ey['premi_kesehatan'],
			
			'ppmp'=>$ey['ppmp'],
			'ppip'=>$ey['ppip'],
			'bank'=>$bank['bank'],
			'rek'=>$ey['norek'],
			
			'ptkp'=>$ey['ptkp_status'].'/'.$ey['ptkp_tanggung'], 
			'npwp'=>$ey['npwp'],
			'jamsostek'=>$ey['jamsostek'],

		);
	}

 
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 15 ,false ); 
}

function get_pos_biaya_label_by_code($code){
	$query = "SELECT label FROM pos_biaya WHERE code ='{$code}'"; 
	$result = my_query($query);
	$row = my_fetch_array($result);
	return $row['label'];
}

function get_tgl_resign($karyawan_id){
	$query = "SELECT * FROM pemberhentian WHERE karyawan_id = {$karyawan_id}";
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['tmt'];
	}
	return false;
}


function set_finger_form($karyawan_id){
	$view = form_header( "finger_Id" , "finger_Id"  );
 	$fields = my_get_data_by_id('a_mesin','karyawan_id',$karyawan_id);
 	$karyawan = loaddata_karyawan( $karyawan_id);
	
	$view .= form_field_display( $karyawan['nik']  , "NIK"  ); 
	$view .= form_field_display( $karyawan['nama']  , "Nama"  ); 
	$finger_id = array(
				'name'=>'finger_id',
				'value'=>( isset($_POST['finger_id']) ? $_POST['finger_id'] : $fields['finger_id'] ),
				'id'=>'finger_id',
				'type'=>'textfield',
				'size'=>'5'
			);
	$form_field_finger_id = form_dynamic($finger_id);
	
	$view .= form_field_display( $form_field_finger_id  , "Finger"  ); 
		$submit = array(
		'value' =>  ' Simpan ' ,
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function set_finger_submit($karyawan_id){
	$new_finger_id = isset($_POST['finger_id']) ? $_POST['finger_id'] : 0;
 	$fields = my_get_data_by_id('a_mesin','karyawan_id',$karyawan_id);
	if($fields){
		$query = "UPDATE a_mesin SET finger_id ='{$new_finger_id}' WHERE mesin_id = {$fields['mesin_id']}";
		return my_query($query);
	}
	my_query("DELETE FROM  a_mesin WHERE finger_id ='{$new_finger_id}' ");
	$datas = array(
		'finger_id' => my_type_data_str($new_finger_id),
		'karyawan_id' => my_type_data_str($karyawan_id),
	);
	return my_insert_record('a_mesin',$datas);
}	

function set_finger_validate(){
	$errsubmit = false;
	$err = array();
	$finger_id = (int) $_POST['finger_id'];
 
	$query = "SELECT * FROM a_mesin a 
		INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id 
		WHERE a.finger_id = {$finger_id}  
		AND a.karyawan_id NOT IN  (  SELECT karyawan_id FROM karyawan_disable   )
	";
	$result = my_query($query);
	if( my_num_rows($result) > 0){
		$errsubmit = true;
		$err[] = "Data finger sudah digunakan";
	} 
 
	if( $errsubmit){
		return $err;
	}
	return $errsubmit;
}